//package com.thekernel.youdaoyun.shiro;
//
//import com.thekernel.youdaoyun.bean.User;
//import com.thekernel.youdaoyun.exception.impl.PasswordNotSameException;
//import com.thekernel.youdaoyun.mapper.UserMapper;
//import com.thekernel.youdaoyun.util.EncryptPassword;
//import org.apache.shiro.authc.*;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.springframework.beans.factory.annotation.Autowired;
//
///**
// * @Author TheKernel
// * @Date 2019/9/16 2:20 下午
// * @Version 1.0
// * @Description
// */
//public class ShiroRealm extends AuthorizingRealm {
//
//    @Autowired
//    private UserMapper userMapper;
//
//    /**
//     * 获取用户 角色 和 权限
//     * @param principalCollection
//     * @return
//     */
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//        return null;
//    }
//
//    /**
//     * 登录认证
//     * @param authenticationToken
//     * @return
//     * @throws AuthenticationException
//     */
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//        // 获取用户输入的用户名和密码
//        String username = (String) authenticationToken.getPrincipal();
//        String password = new String((char[]) authenticationToken.getCredentials());
//
//        User user = this.userMapper.queryUserByUsername(username);
//        password = EncryptPassword.encrypt(password);
//        if (user == null)
//            throw new UnknownAccountException("用户名或密码错误");
//        else if (!user.getPassword().equals(password))
//            throw new IncorrectCredentialsException("用户名或密码错误");
//        else if (user.getStatus().equals(Boolean.FALSE))
//            throw new LockedAccountException("账号已被锁定，请联系管理员 !!!");
//
//        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, password, getName());
//        return info;
//    }
//}
